<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">设备报修</block>
		</cu-custom>

		<view class="bg-white padding" :style="[{height:100+'px'}]">
			<view class="cu-steps">
				<view class="cu-item" :class="index>mainNum?'':index==mainNum?'text-orange':'text-blue'"
					v-for="(item,index) in numList" :key="index" @click="getRepairDetail(index)">
					<text :class="index==num?'icon-radioboxfill':index==mainNum?'icon-usefullfill':'num'"
						:data-index="index + 1"></text> {{item.name}}
				</view>
			</view>
		</view>
		<scroll-view class="bg-white" scroll-y :style="[{height:'calc(100vh - ' + CustomBar + 'px - 100px)'}]">
			<!-- <view class="" :style="isNev?{'pointer-events':'none'}:{}"> -->
			<view class="">
				<block v-if="num ==0">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">1：问题描述</text>
						</view>
						<view class="flex-3">
							<!-- <text class="text-red text-sm">（除保修内容外，其余全部由系统自动带出）</text> -->
						</view>
					</view>
					<view class="padding-sm flex align-center solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修编号：</text>
						</view>
						<view class="flex-3 ">
							<input :disabled="true" :value="equipmentLedger.createdUserId" class="text-sm"
								style="width: 100%;" type="text" placeholder="暂未生成" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修部门：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text" placeholder="请输入"
								v-model="equipmentLedger.createOperOrgName" :disabled="true" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修人：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text"
								:value="equipmentLedger.createOperName" :disabled="true" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修设备：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text"
								v-model="equipmentLedger.equipmentNo" :disabled="true" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">异常类型：</text>
						</view>
						<view class="flex-3">
							<ld-select :disabled="isNev" :multiple="true" :list="options" label-key="label"
								value-key="value" placeholder="请选择" clearable v-model="equipmentLedger.failuresArray"
								@change="selectChange2"></ld-select>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">报修内容：</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<textarea :disabled="isNev" style="width: 100%;height: 70rpx;" maxlength="200"
								v-model="equipmentLedger.reportContent"></textarea>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">故障图片：</text>
						</view>
						<view class="margin-top-sm padding-sm">
							<htz-image-upload :disable="isNev" @imgDelete="imgDelete" :imgLoading="imgLoading" :max="3"
								v-model="ceshiData" data-name="ceshiData" @chooseSuccess="zidingyiSuccess">
							</htz-image-upload>
						</view>
					</view>
					<view style="height: 100rpx;">

					</view>
				</block>
				<block v-else-if="num ==1">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">1：问题描述</text>
						</view>
						<view class="flex-3">
							<!-- <text class="text-red text-sm">（除保修内容外，其余全部由系统自动带出）</text> -->
						</view>
					</view>
					<view class="padding-sm flex align-center solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修编号：</text>
						</view>
						<view class="flex-3 ">
							<input :disabled="true" class="text-sm" style="width: 100%;" type="text" placeholder="暂未生成"
								:value="repairInfo.repairNo" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修部门：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text" :disabled="true" placeholder="请输入"
								v-model="repairInfo.createOperOrgName" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修人：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text" :value="repairInfo.createOperName"
								:disabled="true" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修设备：</text>
						</view>
						<view class="flex-3">
							<input class="text-sm" style="width: 100%;" type="text" v-model="repairInfo.equipmentNo"
								:disabled="true" />
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">故障现象：</text>
						</view>
						<view class="flex-3">
							<text>{{repairInfo.failures}}</text>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">报修内容：</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<view style="width: 100%;height: 70rpx;">
								<text>{{repairInfo.reportContent}}</text>
							</view>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">故障图片：</text>
						</view>
						<view class="margin-top-sm padding-sm">
							<htz-image-upload :disable="true" :imgLoading="imgLoading" :max="3"
								:value="repairInfo.imgArray" data-name="showImgs" @chooseSuccess="zidingyiSuccess">
							</htz-image-upload>
						</view>
					</view>
					<view style="height: 100rpx;">

					</view>
				</block>
				<block v-else-if="num ==2">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">1：接单信息</text>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">接单人：</text>
						</view>
						<view class="flex-3">
							<text class="text-sm">{{repairInfo.lastOrderUserName}}</text>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">报修部门：</text>
						</view>
						<view class="flex-3">
							<text class="text-sm">{{repairInfo.equipmentArea}}</text>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">接单时间：</text>
						</view>
						<view class="flex-3">
							<text class="text-sm">{{repairInfo.lastOrderTime}}</text>
						</view>
					</view>
				</block>
				<block v-else-if="num ==3">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">1：维修内容</text>
						</view>
						<view class="flex-3">
							<!-- <text class="text-red text-sm">（不签到内容无法填写）</text> -->
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">接单人员：</text>
						</view>
						<view class="flex-3">
							<text class="text-sm">{{repairInfo.lastOrderUserName}}</text>
						</view>
					</view>
					<!-- <view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">签到人员：</text>
						</view>
						<view class="flex-3">
							<text class="text-sm">{{repairInfo.lastSignUserName}}</text>
						</view>
					</view> -->
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">主故障：</text>
						</view>
						<view class="flex-3">
							<ld-select :disabled="isNev" :list="options" label-key="label" value-key="value"
								placeholder="请选择" clearable v-model="repairInfo.mainFault"
								@change="mainFaultSelect"></ld-select>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">次故障：</text>
						</view>
						<view class="flex-3">
							<ld-select :disabled="isNev" :multiple="true" :list="options" label-key="label"
								value-key="value" placeholder="请选择" clearable v-model="repairInfo.minorFaultsArray"
								@change="minorFaultsSelect"></ld-select>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">维修时长：</text>
						</view>
						<view class="flex-3">
							<input :disabled="isNev" class="text-sm" maxlength="10" style="width: 100%;" type="number"
								v-model="repairInfo.repairHours" placeholder="分钟" />
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">故障原因：</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<textarea :disabled="isNev" style="width: 100%;height: 70rpx;" maxlength="200"
								v-model="repairInfo.faultReason" placeholder="故障原因"></textarea>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">维修过程说明：</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<textarea :disabled="isNev" style="width: 100%;height: 70rpx;" maxlength="200"
								v-model="repairInfo.repairProcessShow" placeholder="维修过程说明"></textarea>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">维修结果：</text>
						</view>
						<view class="flex-3">
							<ld-select :disabled="isNev" :list="resultOptions" label-key="label" value-key="value"
								placeholder="请选择" clearable v-model="repairInfo.repairResult"
								@change="resultSelect"></ld-select>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">维修结果说明：</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<textarea :disabled="isNev" style="width: 100%;height: 70rpx;" maxlength="200"
								v-model="repairInfo.repairResultShow" placeholder="维修结果说明"></textarea>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">维修图片：</text>
						</view>
						<view class="margin-top-sm padding-sm">
							<htz-image-upload :disabled="isNev" :imgLoading="imgLoading" :max="3"
								v-model="repairInfo.ceshiData" @chooseSuccess="repaorImgSuccess"
								@imgDelete="imgDelete"></htz-image-upload>
						</view>
					</view>
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-red margin-right-xs">*</text>
							<text class="text-bold">维修人：</text>
						</view>
						<view class="flex-3">
							<ld-select :isSearch="true" :multiple="true" :list="repairUserList" label-key="label"
								value-key="value" placeholder="请选择" clearable v-model="repairInfo.allOnWorkArray"
								@change="allOnWorkSelect"></ld-select>
						</view>
					</view>
					<view style="height: 100rpx;">

					</view>
				</block>
				<block v-else-if="num ==4">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">1：生产确认</text>
						</view>
					</view>
					<view class="padding-sm">
						<view class="">
							<text class="text-bold">说明：（选填）</text>
						</view>
						<view class="margin-top-sm solids padding-sm">
							<textarea :disabled="isNev" style="width: 100%;height: 70rpx;" maxlength="200"
								v-model="repairInfo.confirmShow" placeholder="维修结果说明"></textarea>
						</view>
					</view>
				</block>
			</view>
		</scroll-view>
		<view class="cu-modal" :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content">派单</view>
					<view class="action" @tap="hideModal">
						<text class="icon-close text-red"></text>
					</view>
				</view>
				<view class="padding">
					<view class="padding-sm flex solid-bottom">
						<view class="flex-1">
							<text class="text-bold">维修人：</text>
						</view>
						<view class="flex-3">
							<ld-select :disabled="isNev" :isSearch="true" v-if="allOnWork.length>0" :list="allOnWork"
								label-key="label" value-key="value" placeholder="请选择" clearable
								v-model="repairInfo.mainFault" @change="mainFaultSelect"></ld-select>
							<text v-else class="text-grey">暂无可指派人员</text>
						</view>
					</view>
					<view class="flex justify-around align-center margin-top">
						<button class="cu-btn bg-grey" @tap="hideModal">取消</button>
						<button class="cu-btn bg-yellow text-white" @tap="mainCommit">派单</button>
					</view>
				</view>
			</view>
		</view>
		<view v-if="repairDetail.id" class="tpm-bottom-submit flex justify-around align-center">
			<button class="cu-btn bg-grey shadow padding-lr-xl" @tap="goBackMenu">返回</button>
		</view>
		<view v-else class="tpm-bottom-submit flex justify-around align-center"
			:style="[isNev?{'pointer-events':'none'}:{}]">
			<button v-if="num ==2 && !isNev" class="cu-btn bg-grey shadow padding-lr-xl"
				@tap="mainOrderBack">放弃</button>
			<button v-else class="cu-btn bg-grey shadow padding-lr-xl" @tap="goBackMenu">返回</button>
			<block v-if="num == 1 && !isNev">
				<block v-if="userInfo.tenantId == 'SH'">
					<button class="cu-btn bg-yellow text-white shadow padding-lr-xl"
						v-if="userInfo.postCode == 'N4'&&userInfo.equipmentAreaType == repairInfo.equipmentAreaType"
						@tap="showModal">派单</button>
				</block>
				<block v-else>
					<button class="cu-btn bg-yellow text-white shadow padding-lr-xl" v-if="userInfo.postCode == 'N4'"
						@tap="showModal">派单</button>
				</block>
				<!-- <text>{{userInfo.postCodetext> -->
				<block v-if="userInfo.postType == 'REP'">
					<button class="cu-btn bg-blue shadow padding-lr-xl" @tap="mainCommit">接单</button>
				</block>
				<text v-if="isTimeout == 1" class="text-red">(已超过10分钟)</text>
			</block>
			<block v-else-if="num == 2 && !isNev">
				<button :disabled="userInfo.nickName!=repairInfo.lastOrderUserName"
					class="cu-btn bg-blue shadow padding-lr-xl" @tap="mainCommit">
					{{userInfo.nickName!=repairInfo.lastOrderUserName?'无法签到':'签到'}}
				</button>
			</block>
			<block v-else-if="num == 3 && !isNev">
				<block v-if="userInfo.postType == 'REP'">
					<button class="cu-btn bg-blue shadow padding-lr-xl" @tap="mainCommit">提交</button>
				</block>
			</block>
			<block v-else-if="num == 4 && !isNev">
				<block v-if="userInfo.postType == 'PRO'">
					<button class="cu-btn bg-blue shadow padding-lr-xl" @tap="mainCommit">提交</button>
				</block>
			</block>
			<block v-else>
				<button v-if="num != 2 && !isNev" class="cu-btn bg-blue shadow padding-lr-xl"
					@tap="mainCommit">提交</button>
			</block>
		</view>
		<view class="cu-modal" :class="inputModal?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="content text-xxl text-bold">设备编号:</view>
					<view class="action" @tap="hideInputModal">
						<text class="icon-close text-red"></text>
					</view>
				</view>
				<view class="padding">
					<view class="solid-bottom flex flex-direction padding-bottom-sm">
						<input style="width: 100%;" type="text" placeholder="请输入" v-model="inputNo" />
						<text v-if="inputNoCheck" class="text-sm text-red margin-top-sm">{{inputNoCheck}}</text>
					</view>
					<view class="flex justify-center margin-top" style="width: 100%;">
						<button class="cu-btn bg-blue shadow padding-lr-xl" :loading="commitLoading"
							@tap="ScanCodeCommit">提交</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	export default {
		components: {
			htzImageUpload,
		},
		data() {
			return {
				commitLoading: false,
				inputModal: false,
				inputNoCheck: '',
				inputNo: '',
				repairUserList: [],
				isSearch: false,
				repairDetail: this.$helper.repairDetail,
				isNev: false,
				mainNum: '',
				isTimeout: -1,
				signType: this.$helper.signType,
				mainEquipmentLedger: {},
				equipmentNo: this.$helper.equipmentNo,
				modalName: '',
				imgLoading: false,
				repairInfo: {},
				equipmentLedger: {},
				userInfo: this.$helper.userInfo,
				allOnWork: [],
				resultOptions: [],
				options: [],
				value: '',
				value2: [],
				ceshiData: [],
				CustomBar: this.CustomBar,
				tabSelect: 100,
				basics: 0,
				numList: [{
					cuIcon: 'usefullfill',
					name: '报修'
				}, {
					cuIcon: 'radioboxfill',
					name: '接单'
				}, {
					cuIcon: 'roundcheckfill',
					name: '签到'
				}, {
					cuIcon: 'roundcheckfill',
					name: '维修'
				}, {
					cuIcon: 'roundcheckfill',
					name: '生产确认'
				}],
				num: -1,
				scroll: 0
			};
		},
		onLoad(options) {
			let isTimeout = this.$helper.isTimeout;
			if (isTimeout == 1) {
				this.isTimeout = 1;
			}
			// this.repairEquipment();
			if (this.$helper.repairDetail.id) {
				this.isSearch = true;
				this.repairInfo.repairNo = this.$helper.repairDetail.id;
				this.mainNum = this.$helper.repairDetail.num;
				let workComit = {
					pageNum: 1,
					pageSize: 100,
					enableFlag: 1
				}
				this.listAllOnWorkWxg(workComit);
				this.getRepairDetail(0);
			} else {
				this.repairEquipment();
			}
		},
		methods: {
			getRepairDetail(num) {
				var that = this;
				var id = that.repairInfo.repairNo;
				if (num > that.mainNum) {
					return false
				} else {
					if (num == that.mainNum) {
						that.isNev = false;
					} else {
						that.isNev = true;
					}
					// if(that.$helper.repairDetail.id && that.isSearch){
					// 	that.isNev = true;
					// }
				}
				that.$api.repairRepairNo(id).then(async res => {
					let current = 0;
					if (res.code == 0) {
						let equipmentLedger = res.data.equipmentLedger;
						let repairInfo = res.data.repairInfo;
						if (res.data.equipmentLedger) {
							let failureImage = [];
							let failuresArray = [];
							if (repairInfo && repairInfo.failures) {
								failuresArray = repairInfo.failures.split(',');
							}
							if (repairInfo && repairInfo.failureImagePath1) {
								let imgArray = repairInfo.failureImagePath1.split(',');
								for (let j = 0; j < imgArray.length; j++) {
									let returnImg = await that.$api.generateSignedUrl({
										path: imgArray[j]
									});
									if (returnImg.code == 0) {
										failureImage.push(returnImg.data);
									}
								}
							}
							let comitData = {
								createdUserId: repairInfo.repairNo ? repairInfo.repairNo : '',
								createOperName: repairInfo.createOperName ? repairInfo.createOperName :
									that.userInfo.nickName,
								createOperOrgName: equipmentLedger.equipmentAreaType + " " +
									equipmentLedger.productLine + " " + equipmentLedger.station,
								equipmentNo: equipmentLedger.equipmentNo,
								equipmentType: equipmentLedger.equipmentType,
								equipmentArea: equipmentLedger.equipmentArea,
								failureImagePath1: equipmentLedger.failureImagePath1,
								failures: equipmentLedger.failures,
								failuresArray: failuresArray,
								reportContent: equipmentLedger.reportContent
							}
							current = 0;
							that.ceshiData = failureImage;
							that.equipmentLedger = comitData;
							that.mainEquipmentLedger = equipmentLedger;
						}
						if (res.data.repairInfo) {
							let createOperOrgName = repairInfo.createOperOrgName?.split(' ') || [];
							repairInfo.nowRepairStep = num;
							let showImgs = [];
							let failureImage = [];
							let repairImagePath1 = repairInfo.repairImagePath1;
							if (repairImagePath1) {
								let imgArray = repairImagePath1.split(',');
								for (let j = 0; j < imgArray.length; j++) {
									let returnImg = await that.$api.generateSignedUrl({
										path: imgArray[j]
									});
									if (returnImg.code == 0) {
										showImgs.push(returnImg.data);
									}
								}
							}
							let failureImagePath1 = repairInfo.failureImagePath1;
							if (failureImagePath1) {
								let imgArray = failureImagePath1.split(',');
								for (let j = 0; j < imgArray.length; j++) {
									let returnImg = await that.$api.generateSignedUrl({
										path: imgArray[j]
									});
									if (returnImg.code == 0) {
										failureImage.push(returnImg.data);
									}
								}
							}
							repairInfo.ceshiData = showImgs;
							repairInfo.showImgs = showImgs;
							repairInfo.imgArray = failureImage;
							repairInfo.equipmentAreaType = createOperOrgName[0];
							repairInfo.allOnWorkArray = [];
							if (repairInfo.minorFaults) {
								let minorFaultsArray = repairInfo.minorFaults.split(',');
								repairInfo.minorFaultsArray = minorFaultsArray
							}
							if (repairInfo.repairUserIds) {
								repairInfo.allOnWorkArray = repairInfo.repairUserIds.split(',');
							}
							if (res.data.lastOrderUserName) {
								repairInfo.lastOrderUserName = res.data.lastOrderUserName;
							}
							if (res.data.lastOrderTime) {
								repairInfo.lastOrderTime = res.data.lastOrderTime;
							}
							if (res.data.lastSignUserName) {
								repairInfo.lastSignUserName = res.data.lastSignUserName;
							}
							if (res.data.lastSignTime) {
								repairInfo.lastSignTime = res.data.lastSignTime;
							}
							if (repairInfo.nowRepairStep == 1 && that.userInfo.postCode == 'N4') {


								let workComit = {
									pageNum: 1,
									pageSize: 1000,
									isOnline: 1,
									createdOrgId: parseInt(that.userInfo.createdOrgId),
									tenantId: that.userInfo.tenantId,
									equipmentAreaType: createOperOrgName[0],
									limitWorkClass: true,
									enableFlag: 1
								}
								that.listCanOrderUserList(workComit)
							}
							if (repairInfo.nowRepairStep == 3) {
								let workComit = {
									pageNum: 1,
									pageSize: 100,
									enableFlag: 1
									// isOnline: 1,
									// equipmentAreaType: repairInfo.equipmentType
								}
								that.listAllOnWorkWxg(workComit);
								// repairInfo.minorFaultsArray = [];
								// repairInfo.imgArray = [];
								// repairInfo.allOnWorkArray = [];
								repairInfo.comitWorkVal = [];
							}
							repairInfo.defaultOrderUserName = "";
							that.repairInfo = repairInfo;
							current = repairInfo.nowRepairStep;
						}
						that.num = num

						that.repairResultDataList();
						if (that.num != 0) {
							that.sysDictDataList();
						} else {
							let option = [{
									value: '物料问题',
									label: '物料问题'
								},
								{
									value: '质量问题',
									label: '质量问题'
								},
								{
									value: '工艺问题',
									label: '工艺问题'
								},
								{
									value: '设备问题',
									label: '设备问题'
								},
								{
									value: '其他问题',
									label: '其他问题'
								},
							];
							that.options = option;
						}
						if (that.$helper.msgType == 1 && that.num != 1) {
							uni.showModal({
								title: '提示',
								content: '该订单已被接单',
								showCancel: false,
								confirmText: '返回',
								success: res => {
									that.goBackMenu()
								}
							});
						}
					} else {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: res => {
								that.goBackMenu();
							}
						});
					}
				}).catch(error => {})
			},
			TPMcodeScan() {
				// that.$jweixin.scanQRCode({
				// 	needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
				// 	scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码，默认二者都有
				// 	success: function(res) {
				// 		that.equipmentNo = res.resultStr;
				// 		// that.repairEquipment();
				// 		that.$helper.equipmentNo = that.equipmentNo;
				// 		uni.navigateTo({
				// 			url: url
				// 		});
				// 	}
				// })
			},
			judgmentResult() {
				var that = this;
				let fullIndex = that
			},
			showModal(e) {
				var that = this;

				this.modalName = "Modal";
			},
			hideModal(e) {
				this.modalName = null
			},
			uploadImages(src) {
				var that = this;
				return new Promise(function(resolve, reject) {
					// const formData = new FormData();
					let option = {
						// publicRead: true,
						serviceName: "TPM",
						bussinessModule: "repair"
					}

					that.$api.uploadImages('/oss/api/oss/upload', src, 'file', option,
						function(res) {
							resolve(res);
						})
				})
			},
			mainOrderBack() {
				var that = this;
				let repairInfo = that.repairInfo;
				let userInfo = that.userInfo;
				if (userInfo.nickName != repairInfo.lastOrderUserName) {
					uni.showToast({
						title: '非接单人员不可弃单',
						icon: 'none',
						duration: 3000
					});
					return false;
				}
				let comitData = {
					equipmentNo: repairInfo.equipmentNo,
					operateType: "ORDER_BACK",
					repairInfo: {
						repairNo: repairInfo.repairNo
					}
				}
				that.repairCommit(comitData);
			},
			showInputModal() {
				var that = this;
				that.inputModal = true;
			},
			hideInputModal() {
				var that = this;
				that.inputModal = false;
				that.inputNo = '';
				that.inputNoCheck = '';
			},
			ScanCodeCommit() {
				var that = this;
				if (that.num == 2) {
					that.SignInput();
				} else if (that.num == 4) {
					that.ConfirmInput();
				}
			},
			ConfirmInput() {
				var that = this;
				let equipmentNo = that.inputNo;
				if (!equipmentNo) {
					that.inputNoCheck = '请输入设备编号';
					return false;
				} else {
					that.inputNoCheck = '';
				}
				if (that.equipmentNo == equipmentNo) {
					let repairInfo = that.repairInfo;
					let comitData = {
						equipmentNo: repairInfo.equipmentNo,
						operateType: "CONFIRM",
						repairInfo: {
							repairNo: repairInfo.repairNo,
							confirmShow: repairInfo.confirmShow
						}
					}
					that.repairCommit(comitData);
				} else {
					that.inputNoCheck = '设备编号不匹配，请重新输入'
				}
			},
			SignInput() {
				var that = this;
				let equipmentNo = that.inputNo;
				if (!equipmentNo) {
					that.inputNoCheck = '请输入设备编号';
					return false;
				} else {
					that.inputNoCheck = '';
				}
				if (that.equipmentNo == equipmentNo) {
					let repairInfo = that.repairInfo;
					let comitData = {
						equipmentNo: repairInfo.equipmentNo,
						operateType: "SIGN",
						repairInfo: {
							repairNo: repairInfo.repairNo
						}
					}
					that.repairCommit(comitData);
					that.hideInputModal();
				} else {
					that.inputNoCheck = '设备编号不匹配，请重新输入'
				}
			},
			mainCommit() {
				var that = this;
				let comitData = {};
				try {
					if (that.num == 0) {
						let equipmentLedger = that.equipmentLedger;
						if (!equipmentLedger.failuresArray || equipmentLedger.failuresArray.length == 0) {
							uni.showToast({
								title: '请选择故障现象',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						equipmentLedger.failures = equipmentLedger.failuresArray.join(',');
						if (equipmentLedger.imgArray && equipmentLedger.imgArray.length > 0) {
							equipmentLedger.failureImagePath1 = equipmentLedger.imgArray.join(',');
						}
						comitData.equipmentNo = equipmentLedger.equipmentNo;
						comitData.operateType = "CREATE";
						comitData.repairInfo = equipmentLedger;
					} else if (that.num == 1) {
						let repairInfo = that.repairInfo;

						if (that.modalName == "Modal") {
							if (!repairInfo.mainFault) {
								uni.showToast({
									title: '请选择维修工',
									icon: 'none',
									duration: 3000
								});
								return false
							}
							comitData = {
								equipmentNo: repairInfo.equipmentNo,
								operateType: "DEFAULT_ORDER",
								defaultOrderUserId: repairInfo.mainFault,
								repairInfo: {
									repairNo: repairInfo.repairNo
								}
							}
						} else {

							comitData = {
								equipmentNo: repairInfo.equipmentNo,
								operateType: "ORDER",
								repairInfo: {
									repairNo: repairInfo.repairNo
								}
							}
						}
					} else if (that.num == 2) {
						that.showInputModal()
						return false;
					} else if (that.num == 3) {
						let repairInfo = that.repairInfo;
						if (!repairInfo.mainFault) {
							uni.showToast({
								title: '请选择主故障',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						if (!repairInfo.repairHours) {
							uni.showToast({
								title: '请输入维修时长',
								icon: 'none',
								duration: 3000
							});
							return false
						} else if (repairInfo.repairHours < 0) {
							uni.showToast({
								title: '维修时长不能为负数',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						if (!repairInfo.faultReason) {
							uni.showToast({
								title: '请选择故障原因',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						if (!repairInfo.repairProcessShow) {
							uni.showToast({
								title: '请填写维修过程说明',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						if (!repairInfo.repairResultShow) {
							uni.showToast({
								title: '请填写维修结果说明',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						if (!repairInfo.repairResult) {
							uni.showToast({
								title: '请选择维修结果',
								icon: 'none',
								duration: 3000
							});
							return false
						}

						if (repairInfo.minorFaultsArray && repairInfo.minorFaultsArray.length > 0) {
							repairInfo.minorFaults = repairInfo.minorFaultsArray.join(',');
						}
						if (repairInfo.imgArray && repairInfo.imgArray.length > 0) {
							repairInfo.repairImagePath1 = repairInfo.imgArray.join(',');
						}
						let repairUserIds = "";
						let repairUserNames = "";
						let comitWorkVal = repairInfo.comitWorkVal;
						for (let i in comitWorkVal) {
							repairUserIds = repairUserIds + (i == 0 ? '' : ',') + comitWorkVal[i].value;
							repairUserNames = repairUserNames + (i == 0 ? '' : ',') + comitWorkVal[i].label;
						}
						if (!repairUserIds) {
							uni.showToast({
								title: '请选择维修人',
								icon: 'none',
								duration: 3000
							});
							return false
						}
						repairInfo.repairUserIds = repairUserIds;
						repairInfo.repairUserNames = repairUserNames;
						comitData = {
							equipmentNo: repairInfo.equipmentNo,
							operateType: "REPAIR",
							repairInfo: repairInfo
						}

					} else if (that.num == 4) {

						that.showInputModal();

						return false;
					}
					that.repairCommit(comitData);
				} catch (e) {}
			},
			goBackMenu() {
				var that = this;
				if (that.$helper.msgType == 1) {
					uni.reLaunch({
						url: '../menu/menu',
						success() {
							that.$helper.msgType = 0;
						}
					})
				} else {
					uni.navigateBack();
				}
			},
			repairCommit(comitData) {
				var that = this;
				that.commitLoading = true;
				that.$api.repairCommit(comitData).then(res => {
					that.hideModal();
					that.commitLoading = false;
					if (res.code == 0) {
						if (comitData.operateType == "SIGN") {
							that.hideModal();
							uni.showModal({
								title: '提示',
								content: '签到成功',
								showCancel: false,
								confirmText: '返回',
								success: res => {
									that.goBackMenu();
								},
							});
						} else if (comitData.operateType == "ORDER_BACK") {
							uni.showModal({
								title: '提示',
								content: '弃单成功',
								showCancel: false,
								confirmText: '返回',
								success: res => {
									that.goBackMenu();
								},
							});
						} else {
							uni.showModal({
								title: '提示',
								content: '提交成功',
								showCancel: false,
								confirmText: '返回',
								success: res => {
									that.goBackMenu();
								},
							});
						}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			repairResultDataList() {
				var that = this;
				that.$api.sysDictDataList({
					pageNum: '-1',
					andDynamicQueryItems: [{
						criterion: "andEqualTo",
						property: "dictTypeCode",
						value: "REPAIR_RESULT"
					}],
					orderByItems: [{
						orderType: "ASC",
						property: "sortId"
					}],
				}).then(res => {
					if (res.code == 0) {
						let dictDataList = res.data.rows;
						let options = [];
						for (let i in dictDataList) {
							if (dictDataList[i].dictNameZhCn) {
								options.push({
									value: dictDataList[i].dictNameZhCn,
									label: dictDataList[i].dictNameZhCn
								})
							}
						}
						that.resultOptions = options;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			listCanOrderUserList(comitData) {
				var that = this;
				that.$api.listCanOrderUserList(comitData).then(res => {
					if (res.code == 0) {
						let dictDataList = res.data;
						let options = [];
						for (let i in dictDataList) {
							let label = dictDataList[i].fullName;
							let number = dictDataList[i].orderedCnt;
							options.push({
								value: dictDataList[i].id,
								label: label,
								number: number
							})
						}
						that.allOnWork = options;
						that.$forceUpdate();
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			wxgWorkSkillListAllOnWorkWxg(comitData) {
				var that = this;
				that.$api.wxgWorkSkillListAllOnWorkWxg(comitData).then(res => {
					if (res.code == 0) {
						let dictDataList = res.data.rows;
						let options = [];
						for (let i in dictDataList) {
							options.push({
								value: dictDataList[i].id,
								label: dictDataList[i].fullName
							})
						}
						that.allOnWork = options;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			listAllOnWorkWxg(comitData) {
				var that = this;
				that.$api.listAllOnWorkWxg(comitData).then(res => {
					if (res.code == 0) {
						let dictDataList = res.data.rows;
						let options = [];
						for (let i in dictDataList) {
							options.push({
								value: dictDataList[i].id,
								label: dictDataList[i].fullName || dictDataList[i].loginName
							})
						}
						that.repairUserList = options;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			sysDictDataList() {
				var that = this;
				that.$api.sysDictDataList({
					pageNum: '-1',
					andDynamicQueryItems: [{
						criterion: "andEqualTo",
						property: "dictTypeCode",
						value: "FAILURES"
					}],
					orderByItems: [{
						orderType: "ASC",
						property: "sortId"
					}],
				}).then(res => {
					if (res.code == 0) {
						let dictDataList = res.data.rows;
						let options = [];
						for (let i in dictDataList) {
							if (dictDataList[i].dictNameZhCn) {
								options.push({
									value: dictDataList[i].dictNameZhCn,
									label: dictDataList[i].dictNameZhCn
								})
							}
						}
						that.options = options;
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration: 3000
						});
					}
				}).catch(error => {
					uni.showToast({
						title: JSON.stringify(error),
						icon: 'none',
						duration: 3000
					});
				})
			},
			bindDateChange: function(e) {
				this.equipmentLedger.createdTime = e.target.value
			},
			repairEquipment() {
				var that = this;
				that.$api.repairEquipment(that.$helper.equipmentNo).then(async res => {
					let current = 0;
					if (res.code == 0) {
						let equipmentLedger = res.data.equipmentLedger;
						let repairInfo = res.data.repairInfo;
						if (res.data.equipmentLedger) {
							let comitData = {
								createOperName: that.userInfo.nickName,
								createOperOrgName: equipmentLedger.equipmentAreaType + " " +
									equipmentLedger.productLine + " " + equipmentLedger.station,
								equipmentNo: equipmentLedger.equipmentNo,
								equipmentType: equipmentLedger.equipmentType,
								equipmentArea: equipmentLedger.equipmentArea,
								failureImagePath1: equipmentLedger.failureImagePath1,
								failures: equipmentLedger.failures,
								failuresArray: [],
								imgArray: [],
								reportContent: equipmentLedger.reportContent
							}
							current = 0;
							that.equipmentLedger = comitData;
							that.mainEquipmentLedger = equipmentLedger;
						}
						if (res.data.repairInfo) {
							let showImgs = [];
							let failureImage = [];
							let repairImagePath1 = repairInfo.repairImagePath1;
							if (repairImagePath1) {
								let imgArray = repairImagePath1.split(',');
								for (let j = 0; j < imgArray.length; j++) {
									let returnImg = await that.$api.generateSignedUrl({
										path: imgArray[j]
									});
									if (returnImg.code == 0) {
										showImgs.push(returnImg.data);
									}
								}
							}
							let failureImagePath1 = repairInfo.failureImagePath1;
							if (failureImagePath1) {
								let imgArray = failureImagePath1.split(',');
								for (let j = 0; j < imgArray.length; j++) {
									let returnImg = await that.$api.generateSignedUrl({
										path: imgArray[j]
									});
									if (returnImg.code == 0) {
										failureImage.push(returnImg.data);
									}
								}
							}
							repairInfo.showImgs = showImgs;
							repairInfo.imgArray = failureImage;
							if (res.data.lastOrderUserName) {
								repairInfo.lastOrderUserName = res.data.lastOrderUserName;
							}
							if (res.data.lastOrderTime) {
								repairInfo.lastOrderTime = res.data.lastOrderTime;
							}
							if (res.data.lastSignUserName) {
								repairInfo.lastSignUserName = res.data.lastSignUserName;
							}
							if (res.data.lastSignTime) {
								repairInfo.lastSignTime = res.data.lastSignTime;
							}
							if (repairInfo.nowRepairStep == 1 && that.userInfo.postCode == 'N4') {
								// let createOperOrgName = repairInfo.createOperOrgName.split(' ');
								// let workComit = {
								// 	pageNum: 1,
								// 	pageSize: 100,
								// 	isOnline: 1,
								// 	createdOrgId: that.userInfo.createdOrgId,
								// 	tenantId: that.userInfo.tenantId,
								// 	equipmentAreaType: createOperOrgName[0],
								// 	limitWorkClass: true
								// }
								// that.listCanOrderUserList(workComit)
								// that.wxgWorkSkillListAllOnWorkWxg(workComit);

								let createOperOrgName = repairInfo.createOperOrgName.split(' ');
								let workComit = {
									pageNum: 1,
									pageSize: 100,
									isOnline: 1,
									createdOrgId: parseInt(that.userInfo.createdOrgId),
									tenantId: that.userInfo.tenantId,
									equipmentAreaType: createOperOrgName[0],
									limitWorkClass: true,
									enableFlag: 1
								}
								that.listCanOrderUserList(workComit)
							}
							if (repairInfo.nowRepairStep == 3) {
								let workComit = {
									pageNum: 1,
									pageSize: 100,
									enableFlag: 1
									// isOnline: 1,
									// equipmentAreaType: repairInfo.equipmentType
								}
								that.listAllOnWorkWxg(workComit);
								repairInfo.minorFaultsArray = [];
								repairInfo.imgArray = [];
								repairInfo.allOnWorkArray = [];
								repairInfo.comitWorkVal = [];
							}
							repairInfo.defaultOrderUserName = "";
							repairInfo.equipmentAreaType = equipmentLedger.equipmentAreaType;
							that.repairInfo = repairInfo;
							current = repairInfo.nowRepairStep;
						}
						that.num = current;
						that.mainNum = current;
						that.repairResultDataList();
						if (that.num != 0) {
							that.sysDictDataList();
						} else {
							let option = [{
									value: '物料问题',
									label: '物料问题'
								},
								{
									value: '质量问题',
									label: '质量问题'
								},
								{
									value: '工艺问题',
									label: '工艺问题'
								},
								{
									value: '设备问题',
									label: '设备问题'
								},
								{
									value: '其他问题',
									label: '其他问题'
								},
							];
							that.options = option;
						}
						if (that.$helper.msgType == 1 && that.num != 1) {
							uni.showModal({
								title: '提示',
								content: '该订单已被接单',
								showCancel: false,
								confirmText: '返回',
								success: res => {
									that.goBackMenu()
								}
							});
						}
					} else {
						uni.showModal({
							title: '提示',
							content: res.message,
							showCancel: false,
							success: res => {
								that.goBackMenu();
							}
						});
					}
				}).catch(error => {})
			},
			allWorkSelect(val, item) {
				this.repairInfo.mainFault = val;
				// this.$forceUpdate();
			},
			repairUserSelect(val, item) {
				this.repairInfo.repairUserIds = val;
				this.repairInfo.repairUserNames = item.label;
			},
			resultSelect(val) {
				this.repairInfo.repairResult = val
			},
			mainFaultSelect(val) {
				this.repairInfo.mainFault = val
			},
			minorFaultsSelect(val) {
				this.repairInfo.minorFaultsArray = val;
			},
			allOnWorkSelect(val, item, index) {
				let comitWorkVal = this.repairInfo.comitWorkVal;
				if (index != -1) {
					comitWorkVal.splice(index, 1);
				} else {
					comitWorkVal.push(item);
				}
				this.repairInfo.allOnWorkArray = val;
			},
			selectChange2(val) {
				this.equipmentLedger.failuresArray = val
			},
			async zidingyiSuccess(res) {
				var that = this;
				that.imgLoading = true;
				let imgArray = that.equipmentLedger.imgArray;
				let showImgs = [];
				for (let i = 0; i < res.length; i++) {
					let returnImg = await that.uploadImages(res[i]);
					if (returnImg.code == 0) {
						imgArray.push(returnImg.data.resultPath);
					}
				}
				for (let i = 0; i < imgArray.length; i++) {
					if (imgArray[i].indexOf('tiannake-saas') == -1) {
						let returnImg = await that.$api.generateSignedUrl({
							path: imgArray[i]
						});
						if (returnImg.code == 0) {
							showImgs.push(returnImg.data);
						}
					} else {
						showImgs.push(imgArray[i]);
					}
				}
				that.imgLoading = false;
				that.equipmentLedger.imgArray = imgArray;
				that.ceshiData = showImgs;
			},
			async repaorImgSuccess(res) {
				var that = this;
				that.imgLoading = true;
				let imgArray = that.repairInfo.imgArray;
				let showImgs = [];
				for (let i = 0; i < res.length; i++) {
					let returnImg = await that.uploadImages(res[i]);
					if (returnImg.code == 0) {
						imgArray.push(returnImg.data.resultPath);
					}
				}
				for (let i = 0; i < imgArray.length; i++) {
					if (imgArray[i].indexOf('tiannake-saas') == -1) {
						let returnImg = await that.$api.generateSignedUrl({
							path: imgArray[i]
						});
						if (returnImg.code == 0) {
							showImgs.push(returnImg.data);
						}
					} else {
						showImgs.push(imgArray[i]);
					}
				}
				that.imgLoading = false;
				that.repairInfo.imgArray = imgArray;
				that.repairInfo.ceshiData = showImgs;
			},
			imgDelete(data) {
				var that = this;
				let dataName = that.num == 0 ? 'equipmentLedger' : 'repairInfo';
				if (that.num == 0) {
					that.equipmentLedger.imgArray.splice(data.index, 1)
				} else {
					that.repairInfo.imgArray.splice(data.index, 1);
				}
			},
			// BasicsSteps() {
			// 	this.basics= this.basics == this.basicsList.length - 1 ? 0 : this.basics + 1				
			// },
			NumSteps() {
				this.num = this.num == this.numList.length - 1 ? 0 : this.num + 1
			},

			// goBackMenu() {
			// 	uni.reLaunch({
			// 		url: '../menu/menu'
			// 	});
			// 	// this.num = this.num - 1
			// },
			ScrollSteps() {
				this.scroll = this.scroll == 9 ? 0 : this.scroll + 1
			}
		}
	}
</script>

<style>
	.tpm-bottom-submit {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;
		z-index: 100;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>